#include "G.h"
#include "client/windows/client.h"
#include "client/arguments.h"
#include "thread/windows/win32_thread_pool.h"
#include "debug/logger.h"

#include <Windows.h>

namespace renderit
{
	GModule * G = nullptr;

	GModule * create_G(int argc, const char * argv[])
	{
		logger::info("Welcome To RenderIt!\n");

		if (G)
		{
			return G;
		}

		G = new GModule(argc, argv);
		return G;
	}

	GModule::GModule(int argc, const char * argv[])
	{
		arguments_ = get_arguments(argc, argv);

		client_ = new client::windows_client();

		thread_main_ = new thread::win32_main_thread();
		thread_worker_ = new thread::win32_thread_pool("Worker", 8);
		thread_io_ = new thread::win32_thread_pool("IO", 8);
	//	thread_object_ = thread_main_;
	}

	int GModule::loop()
	{
		while (true)
		{
			bool b = client_->loop();

			if (!b)
			{
				break;
			}

			// do work from dispatcher
			thread_main_->do_work();

			::Sleep(1);
		}
		
		return 0;
	}
}